<template>
  <div class="login">
    <!-- 上方标题 -->
    <div class="loginTiltes">
      <h2>胡歌版</h2>登录系统
    </div>
    <!-- from表单 -->
    <div class="Mlogin_box">
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="60px" class="demo-ruleForm mobile_login">
        <el-form-item label="账号：" prop="ruleForm">
          <el-input v-model="ruleForm.username" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="密码：" prop="ruleForm">
          <el-input type="password" v-model="ruleForm.password" autocomplete="off"></el-input>
        </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
            <el-button @click="resetForm('ruleForm')">重置</el-button>
          </el-form-item>
      </el-form>
      <div class="Mlogin_img">
        <el-avatar :src="require('../../../../public/imgs/timg.jpg')"></el-avatar>
      </div>
    </div>
  </div>
</template>

<script>
import {LoginPc} from '../../../api/login'
export default {
    name:'doclogin',
    data() {
      return {
        ruleForm: {
          username: 'wangbaobao',
          password: 'wangbaobao',
        },
        rules: {
          username: [
            { required: true, message: '请输入账号', trigger: 'blur' },
            { min: 3, max: 15, message: '长度在 3 到 5 个字符', trigger: 'blur' }
          ],
          password: [
            { required: true, message: '请选择密码', trigger: 'blur' }
          ]
        }
      };
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
            //判断是否 成功
            if(!valid) return this.$message.error('参数不全')
            //异步请求
            LoginPc(this.ruleForm).then((res)=>{
              console.log(res)
              if(res.data.code!==200) return this.$message.error('登录失败')
              //本地存储 一波数据
              window.sessionStorage.setItem('username',res.data.data.username)
              window.sessionStorage.setItem('token',res.data.data.token)
              localStorage.setItem('doctor_token', res.data.data.token)
              localStorage.setItem('doctor_id', res.data.data.id);
              //跳转一波页面
              this.$router.replace('/dochome')
            })
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
}
</script>

<style>
.login{
  width: 100%;
  height: 100%;
  background: url('../../../../public/imgs/5415.jpg_wh1200.jpg') no-repeat;
  background-size:cover;
  position:relative
}
/* 登录框 */
.Mlogin_box{
  position: relative;
  width: 400px;
  height: 350px;
  background: lightblue;
  border-radius: 15px;
  position: absolute;
  left:50%;
  top:50%;
  transform: translateX(-50%) translateY(-50%);
  text-align: center;
  box-shadow: 1px 1px 6px 10px skyblue;
  opacity: .95;
}
/* 标题 */
.loginTiltes{
  width: 400px;
  height: 50px;
  font-size: 25px;
  border-radius: 15px;
  position: absolute;
  left:50%;
  top:10%;
  transform: translateX(-50%);
  display: flex;
  font-family: 'STLiti';
  align-items: center;
  background: steelblue;
  justify-content: center;
}
.loginTiltes h2{
  font-size: 26px;
  color:palevioletred;
}
/* 表单 */
.Mlogin_input{
  width: 230px;
}
.mobile_login .el-form-item{
  display: flex;
  align-items: center;
  justify-content: center;
}
.mobile_login .el-form-item:nth-child(1){
  margin-top:150px;
}
.mobile_login .el-form-item__content{
  margin:0!important;
}
/* 头像 */
#app .Mlogin_img{
  width: 200px!important;
  height: 200px!important;
  position: absolute;
  left:50%;
  top:50%;
  border-radius: 50%;
  box-shadow: 2px 3px 10px 6px silver;
  transform: translateX(-50%) translateY(-130%);
}
.Mlogin_img .el-avatar,.Mlogin_img img{
  width: 100%;
  height: 100%;
}
</style>
